package com.zgroup.controllers.admin

import com.zgroup.domain.*
import com.zgroup.common.CheckUtils;
class UserController extends AdminDispatchController {
  def scaffoldService
  def userService
  static allowedMethods = [save: "POST", update: "POST", delete: "POST"]
  def beforeInterceptor = [
          action: this.&auth
  ]

  def auth() {
    return super.auth()
  }

  def index = { }

  def businessShow = {
    def user = User.get(params.id);
    def forward = params.forward
    def businessInfo = BusinessInfo.find("from BusinessInfo where user=?", [user]);
    render(view: '/user/businessShow', model: [user: user, bo: businessInfo, forward: forward, forward: forward])
  }

  def saveBusinessInfo = {
    if (userService.saveBusinessInfo(params)) {
      render '1'
    } else {
      render '0'
    }

  }

  def saveCompany = {
    if (userService.saveCompany(params)) {
      render '1'
    } else {
      render '0'
    }
  }

  def bidUser = {
    def view = params.view
    def forward = params.forward
    if (CheckUtils.isEmpty(view)) {
      view = "/${params.property.toLowerCase()}/list"
    }
    render(view: view, model: [list: userService.bidUser(params.date), date: params.date, forward: forward])
  }
}
